package com.haier.cloudremote.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

import com.haier.cloudremote.R;

public class WhetherStudyDialog {
	
	private Context ctx;
	private OnOkClickListener onOkClickListener;
	private Dialog dialog;
	
	public WhetherStudyDialog(Context ctx) {
		super();
		this.ctx = ctx;
		init();
	}

	private void init() {
		// TODO Auto-generated method stub
		dialog = new Dialog(ctx,R.style.dialog);
		LayoutInflater inflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View view = inflater.inflate(R.layout.dialog_whetherstudy, null);
		
		Button btnOk = (Button) view.findViewById(R.id.whetherstudy_button1);
		Button btnCancel = (Button) view.findViewById(R.id.whetherstudy_button2);
		
		btnOk.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				onOkClickListener.onOkClick();
				dismiss();
			}
		});
		btnCancel.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				onOkClickListener.onCancelClick();
				dismiss();
			}
		});
		dialog.setContentView(view);
		dialog.setCancelable(false);
	}
	
	public void show(){
		dialog.show();
	}
	
	private void dismiss(){
		if(dialog!=null){
			if(dialog.isShowing()){
				dialog.dismiss();
			}
		}
	}

	public void setOnOkClickListener(OnOkClickListener onOkClickListener) {
		this.onOkClickListener = onOkClickListener;
	}


}
